/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.GUI.actions;

import controller.Constants;
import controller.commands.AddAttachmentCommand;
import controller.commands.AddTransmitterCommand;
import controller.commands.BasicCommand;
import controller.commands.MacroCommand;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import view.GUI.LabelReader;
import view.GUI.graphic.GraphicView;

/**
 *
 * @author Jelle
 */
public class AddAction extends AbstractAction {

    private GraphicView gview;
    private ArrayList<BasicCommand> commands = new ArrayList<BasicCommand>();
    private Constants cons = new Constants();
    private String s;
    private JFrame frame;

     public AddAction(String s, GraphicView gview, JFrame frame) {
        this.gview = gview;
        this.s=s;
        this.frame=frame;
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("AddAction actionPerformed");
        String[] possibilities = {Object.class.getName(), String.class.getName(), Integer.class.getName(), Double.class.getName()};
        if (s.equals(cons.getTriggerportString())) {
            commands.add(new AddAttachmentCommand(cons.getTriggerportString()));
        } else if (s.equals(cons.getDispatcherportString())) {
            commands.add(new AddAttachmentCommand(cons.getDispatcherportString()));
        } else if (s.equals(cons.getInputportString())) {
            commands.add(new AddAttachmentCommand(cons.getInputportString()));
        } else if (s.equals(cons.getOutputportString())) {
            commands.add(new AddAttachmentCommand(cons.getOutputportString()));
        } else if (s.equals(cons.getValueTransmitterInString())) {
            String name = (String)JOptionPane.showInputDialog(LabelReader.getInstance().getString("NameQuestion"));
            
            String c = (String)JOptionPane.showInputDialog(
                    frame,
                    LabelReader.getInstance().getString("WhichClassQuestion"),
                    LabelReader.getInstance().getString("ChooseAClass"),
                    JOptionPane.PLAIN_MESSAGE, null,
                    possibilities, Object.class
                 );
            commands.add(new AddTransmitterCommand(cons.getValueTransmitterInString(),name,c));
        } else if (s.equals(cons.getValueTransmitterOutString())) {
            String name = (String)JOptionPane.showInputDialog(LabelReader.getInstance().getString("NameQuestion"));

            String c = (String)JOptionPane.showInputDialog(
                    frame,
                    LabelReader.getInstance().getString("WhichClassQuestion"),
                    LabelReader.getInstance().getString("ChooseAClass"),
                    JOptionPane.PLAIN_MESSAGE, null,
                    possibilities, Object.class
                 );
            commands.add(new AddTransmitterCommand(cons.getValueTransmitterOutString(),name,c));
        } else if (s.equals(cons.getTriggerTransmitterInString())) {
            String name = (String)JOptionPane.showInputDialog(LabelReader.getInstance().getString("NameQuestion"));

            commands.add(new AddTransmitterCommand(cons.getTriggerTransmitterInString(),name));
        } else if (s.equals(cons.getTriggerTransmitterOutString())) {
            String name = (String)JOptionPane.showInputDialog(LabelReader.getInstance().getString("NameQuestion"));

            commands.add(new AddTransmitterCommand(cons.getTriggerTransmitterOutString(),name));
        }
        gview.notifyObservers(new MacroCommand(commands));
    }
}
